#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

vector<string> topSort(vector<string> &words)
{
    vector<int> inDeg(26, -1);  
    set<int> mySet;
    vector<vector<int> > adj(26, vector<int>(26, 0));
    
    for (int i = 0; i < words.size(); i++) {
        for (int j = 1; j < words[i].size(); j++) {
            int a = words[i][j-1] - 'A';
            int b = words[i][j] - 'A';
            inDeg[a] = inDeg[a] == -1 ? 0 : inDeg[a];
            inDeg[b] = inDeg[b] == -1 ? 0 : inDeg[b];
            inDeg[b]++;
            adj[a][b] = 1;
        }
    }
    vector<string> ans;
    string cur;
    while(1) {
        bool found = false;
        for (int i = 0; i < 26; i++) {
            if (inDeg[i] == 0) {
                found = true;
                cur += i + 'A';    
                for (int j = 0; j < 26; j++) {
                    if (adj[i][j] != 0) {
                        inDeg[j]--;
                    }
                }
                inDeg[i] = -1;
            }
            
        }
        if (found == false) break;
    }
    cout << cur << endl;
    return ans;
}

int main(int argc, char **argv)
{
    vector<string> words;
    words.push_back("CB");
    words.push_back("BE");
    words.push_back("EF");
    words.push_back("BG");
    vector<string> ans = topSort(words);

    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
}
